{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "12ebc819",
   "metadata": {},
   "source": [
    "# 课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f13bbc09",
   "metadata": {},
   "source": [
    "## 目标：\"Don't panic!\"——\"on tap\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "35b50edd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', \"'\", 't', ' ', 'p']\n",
      "['o', 'n', 't', ' ', 'p']\n",
      "['o', 'n', 't', 'p']\n",
      "['o', 'n', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "# 方法一\n",
    "# 1、将词组转换成列表\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "# 2、删除后面的五个元素a，n，i，c，！用for循环\n",
    "for i in range(5):\n",
    "    plist.pop() #pop()删除默认删除后面\n",
    "# 3、删除\"D\"\n",
    "plist.remove(\"D\")\n",
    "print(plist)\n",
    "# 4、删除第二个的“’”\n",
    "plist.pop(2)\n",
    "print(plist)\n",
    "# 5、删除第三个位置的空格\n",
    "plist.pop(3)\n",
    "print(plist)\n",
    "# 6、在第三个位置插入\"a\"\n",
    "plist.insert(3,'a')\n",
    "print(plist)\n",
    "# 7、第二个位置插入空格\n",
    "plist.insert(2,' ')\n",
    "# 8、最后列表改为词组\n",
    "new_phrase = ''.join(plist)  # 取‘’里的值\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e4a062ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "# 方法二，用切片取值\n",
    "phrase = \"Don't panic!\" #将词转为列表\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "on_str = ''.join(plist[1:3]) #取第一个位置和第二个位置，第三个不取，‘’列表的全部内容\n",
    "print(on_str)\n",
    "new_phrase = on_str+''.join(plist[5]+plist[4]+plist[7]+plist[6]) #取里面所要的单词\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c4dc402",
   "metadata": {},
   "source": [
    "# 用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "af89e64d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "username:ff\n",
      "password:j\n",
      "ff j\n"
     ]
    }
   ],
   "source": [
    "username = input (\"username:\")\n",
    "password = input(\"password:\")\n",
    "print(username,password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "85f6b1b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# info = '''---- INFO OF'''+name+'''-------'''+'''age:'''+age+'''job'''+'''salary'''+salary\n",
    "# print(info)\n",
    "\n",
    "# %s占位符\n",
    "# info = '''------INFO OF %s-------\n",
    "# Name:%s\n",
    "# Age:%s\n",
    "# Job:%s\n",
    "# Salary:%s\n",
    "# '''%(name,name,age,job,salary)\n",
    "# print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ce99cc6",
   "metadata": {},
   "source": [
    "# 变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0883b520",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "# 1、数字\n",
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "db55218f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-10-27\n"
     ]
    }
   ],
   "source": [
    "# 2/字符串，字符串拆分\n",
    "user_input_time = \"2021-10-27\"\n",
    "print(user_input_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ebebc8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3、注释"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83db801f",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
